package de.bwv.javaproject.FunnyTokens.ui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;

import de.java.swing.extension.ui.ExtendedPanel;

/**
 * 
 * @author Patrick Haas
 * @date 24.01.2010
 * 
 * @version 1.0.0
 * 
 */
public class Sidebar extends ExtendedPanel {

	private static final long serialVersionUID = 3074355558567191376L;

	private int vgap;

	/**
	 * Konstruktor.
	 * 
	 * @param hgap
	 *            Horizontale Seperator in Pixel
	 * @param vgap
	 *            Vertikale Seperator in Pixel
	 */
	public Sidebar(int hgap, int vgap) {
		this.vgap = vgap;
		this.setLayout(new FlowLayout(FlowLayout.LEFT, hgap, vgap));
	}

	@Override
	public Component add(Component comp) {
		int increment = vgap;
		if (getComponentCount() == 0) {
			increment = vgap * 2;
		}
		setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height + comp.getPreferredSize().height + increment));
		((SidebarBox) comp).setParent(this);
		return super.add(comp);
	}
}
